﻿using System.Data.Linq;
using System;

namespace RomanJendrusz.Amazon.ETL.Domain
{
    public class Author
    {
        private EntitySet<BookAuthors> bookAuthors;
        private DateTime updated;

        public Author()
        {
            bookAuthors = new EntitySet<BookAuthors>(onAdding, onRemoving);
        }

        private void onRemoving(BookAuthors obj)
        {
            if (obj != null && obj.Author == this)
                obj.Author = null;
        }

        private void onAdding(BookAuthors obj)
        {
            if (obj != null)
                obj.Author = this;
        }

        public int AuthorId { get; set; }
        public string FullName { get; set; }

        /// <summary>
        /// Gets or sets the row updated.
        /// </summary>
        /// <value>The row updated.</value>
        public DateTime Updated
        {
            get { return updated; }
        }

        public EntitySet<BookAuthors> BookAuthors
        {
            get { return bookAuthors; }
            set { bookAuthors.Assign(value); }
        }

        protected bool Equals(Author author)
        {
            if (author == null) return false;
            return FullName.Equals(author.FullName, StringComparison.InvariantCultureIgnoreCase);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as Author);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}